﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Model;

namespace LaKuaShop_TestDemo
{
    /// <summary>
    /// ChangePassword.xaml 的交互逻辑
    /// </summary>
    public partial class ChangePassword : Window
    {
        public ChangePassword()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
            UserInfo user = Common.User;
        }
        //保存按钮
        private void save_Click(object sender, RoutedEventArgs e)
        {
            string oldpass = InitPassword.Password;
            string newpass = password.Password;
            string passakg = againpassword.Password;
            BLL.User User = new BLL.User();
            if (oldpass == "" || newpass == "" || passakg == "")
            {
                PassErrorMsg.IsActive = false;
                AgainErrorMsg.IsActive = false;
                SnackbarsavedChanges.IsActive = false;
                SuccessMsg.IsActive = false;
                BlkErrorMsg.IsActive = true;
                return;
            }
            else if (User.CheckPassword(Common.User.account, oldpass) == -1)
            {
                AgainErrorMsg.IsActive = false;
                BlkErrorMsg.IsActive = false;
                SnackbarsavedChanges.IsActive = false;
                SuccessMsg.IsActive = false;
                PassErrorMsg.IsActive = true;
                return;
            }
            else if (newpass != passakg)
            {
                BlkErrorMsg.IsActive = false;
                PassErrorMsg.IsActive = false;
                SnackbarsavedChanges.IsActive = false;
                SuccessMsg.IsActive = false;
                AgainErrorMsg.IsActive = true;
                return;
            }
            BlkErrorMsg.IsActive = false;
            PassErrorMsg.IsActive = false;
            AgainErrorMsg.IsActive = false;
            SuccessMsg.IsActive = false;
            SnackbarsavedChanges.IsActive = true;
        }
        //关闭按钮
        private void Close_click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        //确认修改按钮
        private void save_Akg_Click(object sender, RoutedEventArgs e)
        {
            string newpass = password.Password;
            BLL.User User = new BLL.User();
            if (User.UpdateUserPass(Common.User, newpass) == -1)
            {
                MessageBox.Show("系统错误，修改失败", "", MessageBoxButton.OKCancel);
                return;
            }
            Common.User.password = newpass;
            SnackbarsavedChanges.IsActive = false;
            SuccessMsg.IsActive = true;
        }


    }
}
